<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>YK Value-added System</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/admin.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/common.css" />
	<script src="<%=basePath%>js/sys/validate.js" type="text/javascript"></script>
	<script src="<%=basePath%>js/json.js" type="text/javascript"></script>
	<script src="<%=basePath%>js/prototype.js" type="text/javascript"></script>
	<script type="text/javascript" charset="utf-8" defer="defer" src="<%=basePath%>js/wdatepicker/WdatePicker.js"></script>
	<script type="text/javascript">
		var judgment;
		function check(){
			if(document.getElementById("name").value==""){
				alert("权限名称不能为空！");
				document.getElementById("name").focus();
				return false ;
			}
			var judgment;
			var name=encodeURIComponent(document.getElementById("name").value);
			var url ="<%=basePath%>admin/system/rightsMgmt/right!checkRightByName.action?name="+name;
	        new Ajax.Request(url,{method:'post',asynchronous:false,
	           	onComplete:function(json){
	           	judgment=json.responseText.parseJSON().judgment;
			    if(judgment=="0"){
			    	alert("该权限名已经存在！");
			    }
	           }
	        });
	        if(judgment=="0"){
		        return false;
	        }else{
		        var parent_id1=document.getElementById("parent_id1").value;
		        var parent_id2=document.getElementById("parent_id2").value;
		        var parent_id3=document.getElementById("parent_id3").value;
		        if(parent_id3!=""){
		        	document.getElementById("parent_id").value=parent_id3;
		        }else if(parent_id2!=""){
		        	document.getElementById("parent_id").value=parent_id2;
		        }else if(parent_id1!=""){
		        	document.getElementById("parent_id").value=parent_id1;
		        }else{
		        	document.getElementById("parent_id").value="0";
		        }
	         	return true;
	        }
		}

		function getRightListByParentID(id,num) {
           	var url = "<%=basePath%>admin/system/rightsMgmt/right!getRightListByParentID.action?parent_id="+id;
           	new Ajax.Request(url,{method:'post',
           		onComplete:function(json){
	           		var subRightList=json.responseText.parseJSON().subRightList;
	            	var subrights=subRightList.split(";");
	            	var objs;
	            	if(num==1){
	            		objs=document.getElementById("parent_id2").options;
	            	}else{
	            		objs=document.getElementById("parent_id3").options;
	            	}
	            	objs.length=0;
	            	objs.add(new Option("--请选择--",""));
	            	for(var i=0;i<subrights.length;i++){
	            		var m=subrights[i].split(":");
	            		var obj=new Option(m[1],m[0]);
	            		objs.add(obj);
	            	}
	           	}
	        });
        }
	</script>
  </head>
  
  <body>
<table width="95%" border="0" align="center" cellspacing="0">
  <tr>
    <td height="30"><table width="100%" border="0">
      <tr>
        <td width="30"><img src="images/location_left.gif" width="24" height="30" /></td>
        <td>
        	您当前的位置是：权限管理 -&gt;增加权限<br>
        </td>
      </tr>
      <tr>
          <td colspan="2"><hr width="80%" align="left"></td>
		</tr>
    </table></td>
  </tr>
  <tr>
    <td><form id="form1" name="form1" method="post" action="<%=basePath%>admin/system/rightsMgmt/right!addRight.action" onsubmit="return check();">
      <table width="100%" border="0" cellspacing="3">
      <tr>
          <td><font color="red" style="font-size:12px;"></font></td>
         <td>
          <font color="red" style="font-size:12px;"><s:actionmessage/><s:actionerror/></font>
          </td>
		</tr>
		<tr>
          <td align="right">
          	<span class="style">*</span>权限名称：
          </td>
          <td colspan="3">
          	<input type="text" style="width:700px" id="name" name="name" value="" maxlength="50"
          		onfocus="currentBackgroundColor=this.style.backgroundColor;this.style.background='#FFFF99';" 
				onblur="this.style.backgroundColor=currentBackgroundColor;" style="height: 25px;"/>   
          </td>
        </tr>
        <tr>
          <td align="right">
          	权限对应的url：
          </td>
          <td colspan="3">
			<textarea rows="3" cols="100" name="url" id="url" onkeyup="if(this.value.length>1000)this.value=this.value.substr(0,500);"
          		onfocus="currentBackgroundColor=this.style.backgroundColor;this.style.background='#FFFF99';" 
				onblur="this.style.backgroundColor=currentBackgroundColor;"></textarea>   
			<input type="hidden" id="parent_id" name="parent_id"/>
          </td>
        </tr>
        <tr>
          <td width="5%" align="right">
          	模块id：
          </td>
          <td width="15%">
          	<select id="module_id" name="module_id">
          		<option value="">--请选择--</option>
          		<s:iterator value="moduleList" id="module">
          			<option value="${module.module_id}" <s:if test="module_id==module.module_id">selected="selected"</s:if>>${module.module_name}</option>
          		</s:iterator>
         	</select>
          </td>
          <td width="5%" align="right">
          	<span class="style">*</span>是否可用：
          </td>
          <td width="15%">
			<input type="radio" name="active" id="active" value="Y" checked/>可用
		   	<input type="radio" name="active" id="active" value="N"/>不可用
          </td>
        </tr>
        <tr>
          <td width="5%" align="right">
          	对应父权限：
          </td>
          <td width="15%">
          	<select id="parent_id1" name="parent_id1" onchange="getRightListByParentID(this.value,1);">
          		<option value="">--请选择--</option>
          		<s:iterator value="rightList1" id="right1">
          			<option value="${right1.id}">${right1.name}</option>
          		</s:iterator>
         	</select>
         	
         	<select id="parent_id2" name="parent_id2" onchange="getRightListByParentID(this.value,2);">
          		<option value="">--请选择--</option>
         	</select>
         	
         	<select id="parent_id3" name="parent_id3">
          		<option value="">--请选择--</option>
         	</select>
          </td>
        </tr>
		<tr>
          <td colspan="4"><hr width="80%" align="left"></td>
		</tr>
        <tr>
          <td align="right"><input type="submit" name="Submit" value="增加" class="Button" /></td>
          <td><input type="button" name="Submit22" value="返回" class="Button"  onclick="history.back();"/></td>
        </tr>
      </table>
        </form>
    </td>
  </tr>
</table>
</body>
</html>
